clear; clc;
% load('Benchmark_SteadyState.mat');
%% Setup
StdVec      =   [1 1 1 -1 -1 60]'*0.01/4;
Param_0     =   struct('KAPPA',0.00/4,'XI',1/82.5/4,'Pir_SS',0.02/4,...
                        'Flag_dE',0,'Flag_Price',0,...
                        'B_Total_SS',0.90,'b_lb',-0.28,...
                        'TrProb_H',0.99,'Prob_H',0.37,...
                        'TrProb_ext',0.99,'Prob_ext',0.43,...
                        'Fin_DomShare',0.84,'Fin_AdjCost',5,...
                        'Cons_FracT',0.3248,'Cons_FracH',0.60,...
                        'RHO_M_dom',0.68,'RHO_M_ext',0.81,'RHO_Y_H',0.95,...
                        'Taylor_Pi',1.1,'Taylor_ir',0.90,...
                        'Cons_ElasTN',5.63,'Cons_ElasHF',5.63);
                    

%% Generate Results under Different Parameter Values

TargetParam =   'Fin_DomShare';
TempList    =   linspace(0,1,11)';

% TargetParam =   'Prob_ext';
% TempList    =   linspace(0.05,0.95,10)';

SOLUTION    =   cell(length(TempList),1);
parfor ii=1:length(TempList)
    Param       =   Param_0;
    Param.(TargetParam)     =   TempList(ii);
    PP          =   Setup_PP(Param);
    SOLUTION{ii}=   Solver_Main(PP,StdVec);
    SOLUTION{ii}.KeyStat ...
                =   TempFun_ConsDistIRF(SOLUTION{ii}.PP,SOLUTION{ii}.SS, ...
                                        SOLUTION{ii}.MODEL,SOLUTION{ii}.EquJac,SOLUTION{ii}.IRF);
end

save(['Exploration_',TargetParam,'.mat'],'SOLUTION','TempList','TargetParam', '-v7.3');



%% Figure
KeyStat     =   zeros(length(SOLUTION{1}.KeyStat),length(SOLUTION));
for ii=1:length(SOLUTION)
    KeyStat(:,ii)   =   SOLUTION{ii}.KeyStat;
end


TitleList   =   {'Cons Diff FI, Dom M', 'Cons Diff FI, Ext M', ...
                 'VarDec FI, Dom M', 'VarDec RI, Ext Y', 'VarDec FI, Ext M'};

N_col       =   5;
N_row       =   1;
fig_size    =   [N_col,N_row].*[1,0.75]*1/2.5; 
fig_gap     =   [0.02,0.02];
fig_VMargin =   [0.20,0.10];
fig_HMargin =   [0.05,0.05]; 

Fig         =   FigureSetup('Comparative Statics',fig_size);
fig_SubPlot =   @(ii_vv)subtightplot(N_row,N_col,ii_vv,...
                                     fig_gap,fig_VMargin,fig_HMargin);
for ii=1:5
    fig_SubPlot(ii);
    plot(TempList,KeyStat(ii,:));
    title(TitleList{ii});
end

print('-depsc','-r1000',Fig,[Folder,TargetParam]);

return
%% Test
Folder      =   'TableGraphs\\Exploration\\';
% TargetParam =   'Fin_DomShare';
TargetParam =   'Prob_ext';
mkdir(Folder);

KeyStat     =   [];
for ii=1:length(SOLUTION)
    KeyStat     =   [KeyStat,TempFun_ConsDistIRF(SOLUTION{ii}.PP,SOLUTION{ii}.SS, ...
                                                 SOLUTION{ii}.MODEL,SOLUTION{ii}.EquJac,SOLUTION{ii}.IRF)];
end


TitleList   =   {'UIP Dev, $\varepsilon_{m}$','UIP Dev, $\varepsilon_{m^{*}}$',...
                 '$\Delta C_{FI} $, $\varepsilon_{m}$','$\Delta C_{FI} $, $\varepsilon_{m^{*}}$',...
                 'VarDec, FI, $\varepsilon_{m}$', ...
                 'VarDec, RI, $\varepsilon_{y^{*}}$',...
                 'VarDec, FI, $\varepsilon_{m^{*}}$'};

N_col       =   4;
N_row       =   2;
fig_size    =   [N_col,N_row].*[1,0.75]*1/2.5; 
fig_gap     =   [0.10,0.02];
fig_VMargin =   [0.20,0.10];
fig_HMargin =   [0.05,0.05]; 

Fig         =   FigureSetup('Comparative Statics',fig_size);
fig_SubPlot =   @(ii_vv)subtightplot(N_row,N_col,ii_vv,...
                                     fig_gap,fig_VMargin,fig_HMargin);
for ii=1:size(KeyStat,1)
    fig_SubPlot(ii);
    plot(TempList,KeyStat(ii,:));
    title(TitleList{ii},'Interpreter','latex');
end

print('-depsc','-r1000',Fig,[Folder,TargetParam]);